package portal.action.rest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.servlet.ModelAndView;

import portal.common.MesageCode;
import portal.common.ResultData;
import portal.common.ShellExec;
import portal.mq.MQProducer;

@RestController
@RequestMapping(value="/conf/test")
public class JobAction {
		private Logger logger= LoggerFactory.getLogger(JobAction.class);
		@RequestMapping(value="/update",method=RequestMethod.GET)
		
		public ResultData updateConf(HttpServletRequest request,HttpServletResponse response){
			// TODO Analysis Request Data
			
			// TODO Send the message of Request Data
			int i=0;
			while(i<10){
				try {
					MQProducer.sendMessage("test");
					return ResultData.getInstance();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					i++;
					//return ResultData(ResultCode.UNKNOWN_ERROR,"");
				}
				logger.error("Message will try to send 10 times .updateConf message send Error ("+i+"/10),see more errors in the stacktrace.");
			}
			return new ResultData(MesageCode.UNKNOWN_ERROR,"Message Send Error");
		}
		/*****
		 * 调用执行 命令的action
		 * 命令参数，根据前端内容获取
		 * ****/
		@RequestMapping(value="/cmdexec",method=RequestMethod.POST)		
		public ResultData remoteCmdExec(HttpServletRequest request,HttpServletResponse response){
			ShellExec.callShell("ls");
			return ResultData.getInstance();
		}
}
